package testLayer;

import static org.junit.Assert.*;
import modelLayer.Subject;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import controlLayer.SubjectCtr;
import dbLayer.DBTeacher;

public class SubjectControllerTest {
	
	private SubjectCtr subjectCtr;
	private boolean retrieveAssociation = true;
	
	@Before
	public void setUp() throws Exception {
		
		this.subjectCtr = new SubjectCtr();
		this.insert();
		
	}
	
	@After
	public void tearDown() throws Exception {
		
		this.remove();
		this.subjectCtr = null;
		
	}
	
	public void insert() throws Exception {
		
	//	this.subjectCtr.createSubject("Sport", "blank", new DBTeacher().findById(1));	 
		
	}
	
	@Test
	public void find() throws Exception {
//		
//		if (retrieveAssociation) {
//		assertTrue(this.subjectCtr.findSubject("Sport", retrieveAssociation).getTeacher() != null);
//		}
//		else {
//			assertTrue(this.subjectCtr.findSubject("Sport", retrieveAssociation) != null);
//		}		
		
	}
	
	@Test
	public void findById() throws Exception {
		
//		if (retrieveAssociation) {
//			assertTrue(this.subjectCtr.findById(this.subjectCtr.findSubject("Sport", false).getId(),
//									  	 retrieveAssociation).getTeacher() != null);
//		}
//		else {
//			assertTrue(this.subjectCtr.findById(this.subjectCtr.findSubject("Sport", false).getId(),
//									  	 retrieveAssociation) != null);
//		}

	}
	
	@Test
	public void getAll() throws Exception {
		
		boolean test = true;
//		if (retrieveAssociation) {			
//			for (Subject s : this.subjectCtr.getAll(retrieveAssociation)) {
//				if (s.getTeacher() == null) {
//					test = false;
//				}
//			}
//		}
//		else {
//			if (this.subjectCtr.getAll(retrieveAssociation).isEmpty() &&
//				!(this.subjectCtr.getAll(retrieveAssociation).size() >= 1)) {
//				test = true;
//			}
//		}
//		
//		assertTrue(test);
		
	}
	
	@Test
	public void update() throws Exception {
		
		assertTrue(this.subjectCtr.updateSubject(this.subjectCtr.findSubject("Sport", false)) > 0);
		
	}
	
	public void remove() throws Exception {
			
		this.subjectCtr.removeSubject(this.subjectCtr.findSubject("Sport", false));
		
	} 

}
